/**
 * @作者 伟子涵
 * @微信公号 搬砖暗夜码农
 * @开源项目 $ https://gitee.com/zhouwei5208888
 * @我的博客 $ http://itzhouwei.com
 * @创建时间 2023/11/30 18:39
 */
package com.itzhouwei.mybatis.binding;

import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @description: MapperProxy 映射器 代理类
 * @author：zw，微信：yingshengzw
 * @date: 2023/11/30 18:39
 * @Copyright： 公众号：搬砖暗夜码农 | 博客：https://itzhouwei.com - 沉淀、分享、成长，让自己和他人都能有所收获！
 */

@SuppressWarnings("all")
public class MapperProxy<T> implements InvocationHandler, Serializable {


    @Serial
    private static final long serialVersionUID = 6661549169496596073L;

    private Map<String,String> sqlSession;
    private final Class<T> mapperInterface;

    MapperProxy(Class<T> mapperInterface, Map<String,String> sqlSession) {
        this.mapperInterface = mapperInterface;
        this.sqlSession = sqlSession;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())){
            return method.invoke(this, args);
        }
        return "你被代理了!" +sqlSession.get(method.getName())+"."+method.getName();
    }
}
